﻿namespace HRM.CORE.REPORT
{
    using APP.HELPER.Utils.Security;
    using DevExpress.Utils;
    using DevExpress.XtraCharts;
    using DevExpress.XtraPrinting;
    using DevExpress.XtraReports.UI;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Drawing.Printing;

    public class rptChartBase : XtraReport
    {
        private BottomMarginBand BottomMargin;
        private XRChart chart;
        private IContainer components;
        private DetailBand Detail;
        private XRLabel lbTitle;
        private DataTable m_DataChart;
        private string m_NameChart;
        private int m_Type;
        private PageFooterBand PageFooter;
        private XRPictureBox ptPhoto;
        private TopMarginBand TopMargin;
        private XRLabel txtAddress;
        private XRLabel txtCompany;
        private XRLabel txtDate;
        private XRLabel xrLabel2;
        private XRLabel xrLabel3;
        private XRTable xrTable3;
        private XRTableCell xrTableCell10;
        private XRTableCell xrTableCell12;
        private XRTableCell xrTableCell7;
        private XRTableCell xrTableCell9;
        private XRTableRow xrTableRow3;
        private XRTableRow xrTableRow4;

        public rptChartBase()
        {
            this.m_Type = 0;
            this.m_DataChart = new DataTable();
            this.m_NameChart = "";
            this.components = null;
            this.InitializeComponent();
        }

        public rptChartBase(int Type, DataTable DataChart, string NameChart)
        {
            this.m_Type = 0;
            this.m_DataChart = new DataTable();
            this.m_NameChart = "";
            this.components = null;
            this.InitializeComponent();
            this.m_Type = Type;
            this.m_DataChart = DataChart;
            this.m_NameChart = NameChart;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            XYDiagram diagram = new XYDiagram();
            Series series = new Series();
            SideBySideBarSeriesLabel label = new SideBySideBarSeriesLabel();
            Series series2 = new Series();
            SideBySideBarSeriesLabel label2 = new SideBySideBarSeriesLabel();
            SideBySideBarSeriesLabel label3 = new SideBySideBarSeriesLabel();
            this.Detail = new DetailBand();
            this.xrLabel3 = new XRLabel();
            this.xrTable3 = new XRTable();
            this.xrTableRow3 = new XRTableRow();
            this.xrTableCell7 = new XRTableCell();
            this.xrTableCell9 = new XRTableCell();
            this.xrTableRow4 = new XRTableRow();
            this.xrTableCell10 = new XRTableCell();
            this.xrTableCell12 = new XRTableCell();
            this.txtDate = new XRLabel();
            this.chart = new XRChart();
            this.txtCompany = new XRLabel();
            this.xrLabel2 = new XRLabel();
            this.txtAddress = new XRLabel();
            this.ptPhoto = new XRPictureBox();
            this.lbTitle = new XRLabel();
            this.TopMargin = new TopMarginBand();
            this.BottomMargin = new BottomMarginBand();
            this.PageFooter = new PageFooterBand();
            this.xrTable3.BeginInit();
            this.chart.BeginInit();
            ((ISupportInitialize) diagram).BeginInit();
            ((ISupportInitialize) series).BeginInit();
            ((ISupportInitialize) label).BeginInit();
            ((ISupportInitialize) series2).BeginInit();
            ((ISupportInitialize) label2).BeginInit();
            ((ISupportInitialize) label3).BeginInit();
            this.BeginInit();
            this.Detail.Controls.AddRange(new XRControl[] { this.xrLabel3, this.xrTable3, this.txtDate, this.chart, this.txtCompany, this.xrLabel2, this.txtAddress, this.ptPhoto, this.lbTitle });
            this.Detail.HeightF = 775f;
            this.Detail.Name = "Detail";
            this.Detail.Padding = new PaddingInfo(0, 0, 0, 0, 100f);
            this.Detail.TextAlignment = TextAlignment.TopLeft;
            this.xrLabel3.Font = new Font("Times New Roman", 10.25f, FontStyle.Italic | FontStyle.Bold);
            this.xrLabel3.LocationFloat = new PointFloat(351.8858f, 555.75f);
            this.xrLabel3.Name = "xrLabel3";
            this.xrLabel3.Padding = new PaddingInfo(2, 2, 0, 0, 100f);
            this.xrLabel3.SizeF = new SizeF(390.3641f, 18.20831f);
            this.xrLabel3.StylePriority.UseFont = false;
            this.xrLabel3.StylePriority.UseTextAlignment = false;
            this.xrLabel3.Text = "............, ng\x00e0y ....... th\x00e1ng ........ năm ...............";
            this.xrLabel3.TextAlignment = TextAlignment.BottomCenter;
            this.xrTable3.Font = new Font("Times New Roman", 10.25f);
            this.xrTable3.LocationFloat = new PointFloat(0.9999911f, 575.9583f);
            this.xrTable3.Name = "xrTable3";
            this.xrTable3.Rows.AddRange(new XRTableRow[] { this.xrTableRow3, this.xrTableRow4 });
            this.xrTable3.SizeF = new SizeF(742.2499f, 62.5f);
            this.xrTable3.StylePriority.UseFont = false;
            this.xrTableRow3.Cells.AddRange(new XRTableCell[] { this.xrTableCell7, this.xrTableCell9 });
            this.xrTableRow3.Name = "xrTableRow3";
            this.xrTableRow3.Weight = 1.0;
            this.xrTableCell7.Font = new Font("Times New Roman", 10.25f, FontStyle.Bold);
            this.xrTableCell7.Name = "xrTableCell7";
            this.xrTableCell7.StylePriority.UseFont = false;
            this.xrTableCell7.StylePriority.UseTextAlignment = false;
            this.xrTableCell7.Text = "Ph\x00f2ng HCNS";
            this.xrTableCell7.TextAlignment = TextAlignment.MiddleCenter;
            this.xrTableCell7.Weight = 1.4309860970491313;
            this.xrTableCell9.Font = new Font("Times New Roman", 10.25f, FontStyle.Bold);
            this.xrTableCell9.Name = "xrTableCell9";
            this.xrTableCell9.StylePriority.UseFont = false;
            this.xrTableCell9.StylePriority.UseTextAlignment = false;
            this.xrTableCell9.Text = "Người lập biểu đồ";
            this.xrTableCell9.TextAlignment = TextAlignment.MiddleCenter;
            this.xrTableCell9.Weight = 1.5960649703891576;
            this.xrTableRow4.Cells.AddRange(new XRTableCell[] { this.xrTableCell10, this.xrTableCell12 });
            this.xrTableRow4.Name = "xrTableRow4";
            this.xrTableRow4.Weight = 1.0;
            this.xrTableCell10.Font = new Font("Times New Roman", 9.75f, FontStyle.Italic);
            this.xrTableCell10.Name = "xrTableCell10";
            this.xrTableCell10.StylePriority.UseFont = false;
            this.xrTableCell10.StylePriority.UseTextAlignment = false;
            this.xrTableCell10.Text = "(K\x00fd, đ\x00f3ng dấu v\x00e0 ghi r\x00f5 họ t\x00ean)";
            this.xrTableCell10.TextAlignment = TextAlignment.TopCenter;
            this.xrTableCell10.Weight = 1.4309859725920413;
            this.xrTableCell12.Font = new Font("Times New Roman", 9.75f, FontStyle.Italic);
            this.xrTableCell12.Name = "xrTableCell12";
            this.xrTableCell12.StylePriority.UseFont = false;
            this.xrTableCell12.StylePriority.UseTextAlignment = false;
            this.xrTableCell12.Text = "(K\x00fd v\x00e0 ghi r\x00f5 họ t\x00ean)";
            this.xrTableCell12.TextAlignment = TextAlignment.TopCenter;
            this.xrTableCell12.Weight = 1.596065094846248;
            this.txtDate.LocationFloat = new PointFloat(0f, 99.79166f);
            this.txtDate.Name = "txtDate";
            this.txtDate.Padding = new PaddingInfo(2, 2, 0, 0, 100f);
            this.txtDate.SizeF = new SizeF(742.2499f, 23f);
            this.txtDate.StylePriority.UseTextAlignment = false;
            this.txtDate.Text = "Th\x00e1ng 00 - năm 0000";
            this.txtDate.TextAlignment = TextAlignment.MiddleCenter;
            this.chart.BorderColor = SystemColors.ControlText;
            this.chart.Borders = BorderSide.None;
            diagram.AxisX.Range.SideMarginsEnabled = true;
            diagram.AxisX.VisibleInPanesSerializable = "-1";
            diagram.AxisY.Range.SideMarginsEnabled = true;
            diagram.AxisY.VisibleInPanesSerializable = "-1";
            this.chart.Diagram = diagram;
            this.chart.LocationFloat = new PointFloat(0f, 126.4583f);
            this.chart.Name = "chart";
            label.LineVisible = true;
            series.Label = label;
            series.Name = "Series 1";
            label2.LineVisible = true;
            series2.Label = label2;
            series2.Name = "Series 2";
            this.chart.SeriesSerializable = new Series[] { series, series2 };
            label3.LineVisible = true;
            this.chart.SeriesTemplate.Label = label3;
            this.chart.SizeF = new SizeF(742.2499f, 416.6667f);
            this.txtCompany.Font = new Font("Times New Roman", 9.75f, FontStyle.Bold);
            this.txtCompany.LocationFloat = new PointFloat(93.91676f, 10.00001f);
            this.txtCompany.Name = "txtCompany";
            this.txtCompany.Padding = new PaddingInfo(2, 2, 0, 0, 100f);
            this.txtCompany.SizeF = new SizeF(648.3333f, 17.70833f);
            this.txtCompany.StylePriority.UseFont = false;
            this.txtCompany.Text = "txtCompany";
            this.xrLabel2.LocationFloat = new PointFloat(93.91676f, 31.70837f);
            this.xrLabel2.Name = "xrLabel2";
            this.xrLabel2.Padding = new PaddingInfo(2, 2, 0, 0, 100f);
            this.xrLabel2.SizeF = new SizeF(52.79146f, 17.70833f);
            this.xrLabel2.Text = "Địa Chỉ:";
            this.txtAddress.LocationFloat = new PointFloat(146.7082f, 31.70837f);
            this.txtAddress.Name = "txtAddress";
            this.txtAddress.Padding = new PaddingInfo(2, 2, 0, 0, 100f);
            this.txtAddress.SizeF = new SizeF(595.5417f, 17.70833f);
            this.txtAddress.Text = "txtAddress";
            this.ptPhoto.LocationFloat = new PointFloat(2.375f, 4.999987f);
            this.ptPhoto.Name = "ptPhoto";
            this.ptPhoto.SizeF = new SizeF(88.54166f, 58.33333f);
            this.ptPhoto.Sizing = ImageSizeMode.ZoomImage;
            this.lbTitle.Font = new Font("Times New Roman", 16f, FontStyle.Bold);
            this.lbTitle.LocationFloat = new PointFloat(0.375f, 69.54163f);
            this.lbTitle.Name = "lbTitle";
            this.lbTitle.Padding = new PaddingInfo(2, 2, 0, 0, 100f);
            this.lbTitle.SizeF = new SizeF(743f, 30.25002f);
            this.lbTitle.StylePriority.UseFont = false;
            this.lbTitle.StylePriority.UseTextAlignment = false;
            this.lbTitle.Text = "BIỂU ĐỒ THỐNG K\x00ca";
            this.lbTitle.TextAlignment = TextAlignment.MiddleCenter;
            this.TopMargin.HeightF = 20f;
            this.TopMargin.Name = "TopMargin";
            this.TopMargin.Padding = new PaddingInfo(0, 0, 0, 0, 100f);
            this.TopMargin.TextAlignment = TextAlignment.TopLeft;
            this.BottomMargin.HeightF = 20f;
            this.BottomMargin.Name = "BottomMargin";
            this.BottomMargin.Padding = new PaddingInfo(0, 0, 0, 0, 100f);
            this.BottomMargin.TextAlignment = TextAlignment.TopLeft;
            this.PageFooter.HeightF = 0f;
            this.PageFooter.Name = "PageFooter";
            base.Bands.AddRange(new Band[] { this.Detail, this.TopMargin, this.BottomMargin, this.PageFooter });
            base.Font = new Font("Times New Roman", 9.75f);
            base.Margins = new System.Drawing.Printing.Margins(0x2d, 0x26, 20, 20);
            base.PageHeight = 0x491;
            base.PageWidth = 0x33b;
            base.PaperKind = PaperKind.A4;
            base.Version = "9.3";
            this.BeforePrint += new PrintEventHandler(this.rptChartAge_BeforePrint);
            this.xrTable3.EndInit();
            ((ISupportInitialize) diagram).EndInit();
            ((ISupportInitialize) label).EndInit();
            ((ISupportInitialize) series).EndInit();
            ((ISupportInitialize) label2).EndInit();
            ((ISupportInitialize) series2).EndInit();
            ((ISupportInitialize) label3).EndInit();
            this.chart.EndInit();
            this.EndInit();
        }

        public void LoadChart(int Type, DataTable DataChart)
        {
            Series series;
            SeriesPoint point;
            this.m_DataChart = DataChart;
            this.m_Type = Type;
            this.chart.Series.Clear();
            if (this.m_Type == 0)
            {
                foreach (DataRow row in this.m_DataChart.Rows)
                {
                    series = new Series(row[0].ToString(), ViewType.Bar);
                    point = new SeriesPoint(row[0].ToString(), new double[] { double.Parse(row[1].ToString()) });
                    series.Points.Add(point);
                    this.chart.Series.Add(series);
                }
            }
            else if (this.m_Type == 1)
            {
                series = new Series(" ", ViewType.Pie) {
                    PointOptions = { PointView = PointView.ArgumentAndValues }
                };
                foreach (DataRow row in this.m_DataChart.Rows)
                {
                    point = new SeriesPoint(row[0].ToString(), new double[] { double.Parse(row[1].ToString()) });
                    series.Points.Add(point);
                }
                this.chart.Series.Add(series);
                series.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
                series.PointOptions.ValueNumericOptions.Precision = 0;
            }
            else if (this.m_Type == 2)
            {
                foreach (DataRow row in this.m_DataChart.Rows)
                {
                    series = new Series(row[0].ToString(), ViewType.Bar3D);
                    point = new SeriesPoint(row[0].ToString(), new double[] { double.Parse(row[1].ToString()) });
                    series.Points.Add(point);
                    this.chart.Series.Add(series);
                }
            }
            else if (this.m_Type == 3)
            {
                series = new Series(" ", ViewType.Pie3D) {
                    PointOptions = { PointView = PointView.ArgumentAndValues }
                };
                foreach (DataRow row in this.m_DataChart.Rows)
                {
                    point = new SeriesPoint(row[0].ToString(), new double[] { double.Parse(row[1].ToString()) });
                    series.Points.Add(point);
                }
                this.chart.Series.Add(series);
                series.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
                series.PointOptions.ValueNumericOptions.Precision = 0;
            }
        }

        private void rptChartAge_BeforePrint(object sender, PrintEventArgs e)
        {
            this.LoadChart(this.m_Type, this.m_DataChart);
            this.lbTitle.Text = "BIỂU ĐỒ THỐNG K\x00ca THEO " + this.m_NameChart.ToUpper();
            this.txtDate.Text = "Th\x00e1ng " + DateTime.Now.Month.ToString() + " - Năm " + DateTime.Now.Year.ToString();
            ////if (MyInfo.Get(MyEncryption.Encrypt("ERP01", "123654", true)) == "OK")
            {
                this.txtCompany.Text = "";//MyInfo.Company.ToUpper();
                this.txtAddress.Text = "";// MyInfo.Address;
                this.ptPhoto.Image = null;//MyInfo.Photo;
            }
        }
    }
}

